package com.imiku.repository;

import com.imiku.model.RoleInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RoleInfoRepository extends JpaRepository<RoleInfo, Integer> {

    @Query(value = "select role_key FROM role_info where role_id in (SELECT role_id FROM user_role where user_id = ?1)", nativeQuery = true)
    List<String> findByUserId(Integer userId);

    @Query(value = "select role_key FROM role_info where role_id in (SELECT role_id FROM menu_role where menu_id = ?1)", nativeQuery = true)
    String[] findByMenuId(Integer id);

    RoleInfo findByRoleId(int roleId);
}
